<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

    <title>会员信息管理</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header"><h4>粉丝添加</h4></div>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="home">

                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>会员ID:</label>
                                <input type="text" class="form-control" name="memberId">
                            </div>
                            <div class="form-group">
                                <label>会员名称:</label>
                                <input type="text" class="form-control" name="memberName">
                            </div>
                            <div class="form-group">
                                <label>联系电话:</label>
                                <input type="text" class="form-control" name="memberPhone">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round"  type="button" id="searchFormBtn" >查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="addSuperiorBtn">添加上级</button>
                            </div>
                        </form>
                        <table id="info_data"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" >
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm"  method="post">
                        <input type="hidden" name="id">
                        <div class="row">
                            <div class="col-xs-12">
                                <label for="leaderId" class="control-label">上级会员Id：</label>
                                <input type="text" class="form-control" id="leaderId" name="leaderId" placeholder="内容不能为空">
                            </div>
                        </div>

                    </form>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" id="saveFormBtn" class="btn btn-primary">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>





<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
<script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>

<script type="text/javascript">

    //设置表头
    var columns = [
        {checkbox: true},
        {field: 'memberId',title: '会员ID'},
        {field: 'memberAccount',title: '会员账号'},
        {field: 'memberName',title: '会员名称'},
        {field: 'gradeId',title: '会员等级',formatter: function (value, row, index) {
                if (value==0){
                    return "合作商家"
                }else if(value==1){
                    return "联盟商家"
                }else if(value==2){
                    return "联盟企业"
                }else if(value==3){
                    return "粉丝"
                }else if(value==4){
                    return "创业VIP"
                }
            }},
        {field: 'sex',title: '性别',formatter: function (value, row, index) {
                if (value==0){
                    return "女"
                }else if(value==1){
                    return "男"
                }else {
                    return "无"
                }
            }},
        {field: 'memberPhone',title: '联系电话'},
        {field: 'leaderId',title: '上级ID',formatter:function (value) {

                if (value != null){
                    return value;
                }else {
                    return  "无";
                }
            }},
        {field: 'memberEmail',title: '会员邮箱',formatter:function (value) {
                if (value != null){
                    return value;
                }else {
                    return  "无";
                }
            }},
        {field: 'address',title: '常住地址',formatter:function (value) {
                if (value != null){
                    return value;
                }else {
                    return  "无";
                }
            }},
        {field: 'birthday',title: '会员生日',formatter:function (value) {
                if (value != null){
                    return value;
                }else {
                    return  "无";
                }
            }},
        {field: 'registerTime',title: '注册时间',formatter: function (value) {
                return zero2one.dateFormat(value, 'Y-m-d H:i:s')}}
    ];


    //进入主界面加载数据
    zero2one.datagrid("info_data", "/remote/memberInfo/queryInfo",function (params) {
        return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
    }, columns);

    //点击查询按钮重新加载页面数据
    $("#searchFormBtn").click(function () {
        $('#info_data').bootstrapTable('refresh');
    });


    //点击添加按钮弹出模态框
    $("#addSuperiorBtn").click(function () {

        var datas = $('#info_data').bootstrapTable('getSelections');

        if (datas.length ==1){

            if (datas[0].leaderId==null){
                $("#addOrEditForm")[0].reset();
                $("#addOrEditModal").modal("show");
            }else{
                $.messager.alert("温馨提示", "本账号已有上级不可添加");

            }
        }else {
            $.messager.alert("温馨提示", "请选择一条数据操作");

        }

    });


    $('#addOrEditForm').bootstrapValidator({
        fields: {
            leaderId: {validators: {notEmpty: {message: '添加上级账号不能为空'}}},
        }
    });

    //保存
    $("#saveFormBtn").click(function () {

        var ok= $('#leaderId').val();
        var bv = $('#addOrEditForm').data('bootstrapValidator');
        bv.validate();
        //获取选中行的数据
        var datas = $('#info_data').bootstrapTable('getSelections');
        if (ok!=''){
            if (bv.isValid()) {
                zero2one.request("/remote/memberInfo/addLeader", {
                    "memberId": datas[0].memberId,
                    "memberName": datas[0].memberName,
                    "gradeId": datas[0].gradeId,
                    "leaderId": ok,
                }, function (data) {
                    window.setTimeout("window.location.reload()", 1000);//延迟1秒刷新
                });
            }
        }else {
            console.log("上级id不能为空");

        }

    });


</script>
</div>
</body>
</html>
